﻿using System;
using System.Collections.Generic;

using IDAL.AuthModel;
using Model.AuthModel;
using DALFactory.AuthModel;
namespace BLL.AuthModel
{
    /// <summary>
    /// 通用组件，权限模型，业务层，成员角色
    /// </summary>
    public class StaffRolesBLL
    {
        private IStaffRoles dal = DataAccess.CreateStaffRole();

        /// <summary>
        /// 更新成员角色
        /// </summary>
        /// <param name="staffID"></param>
        /// <param name="rolesList"></param>
        /// <returns></returns>
        public bool UpdateStaffRoles(int staffID, string rolesList) 
        {
            return dal.UpdateStaffRoles(staffID, rolesList);
        }

        /// <summary>
        /// 根据角色获取成员
        /// </summary>
        /// <param name="rolesID"></param>
        /// <param name="key"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public IList<StaffRolesInfo> ListStaffByRoles(int rolesID, string key, int pageIndex, int pageSize, out int recordCount)
        {
            StaffRolesCondition condition = new StaffRolesCondition();
            condition.RolesID = rolesID;
            condition.KeyWord = key;
            condition.PageIndex = pageIndex;
            condition.PageSize = pageSize;
            condition.OrderBy = "StaffRolesID DESC";
            return dal.ListStaffRoles(condition, out recordCount);
        }

        /// <summary>
        /// 获取成员具有的角色
        /// </summary>
        /// <param name="staffID"></param>
        /// <returns></returns>
        public IList<StaffRolesInfo> ListRolesByStaff(int staffID)
        {
            StaffRolesCondition condition = new StaffRolesCondition();
            condition.StaffID = staffID;
            condition.OrderBy = "StaffRolesID DESC";
            return dal.ListStaffRoles(condition);
        }

        /// <summary>
        /// 检查用户权限
        /// </summary>
        /// <param name="staffID"></param>
        /// <param name="path"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public bool CheckRolesAuthByStaff(int staffID, string moduleLink, string funcName)
        {
            return dal.CheckRolesAuthByStaff(staffID, moduleLink, funcName);
        }

        /// <summary>
        /// 获取成员具有的模块类别
        /// </summary>
        /// <param name="staffID"></param>
        /// <returns></returns>
        public IList<StaffRolesInfo> ListModuleTypeByStaff(int staffID)
        {
            StaffRolesCondition condition = new StaffRolesCondition();
            condition.StaffID = staffID;
            condition.ModuleMenu = "y";
            condition.FuncMenu = "y";
            condition.OrderBy = "ModuleTypeID DESC";
            return dal.ListRolesAuthModuleTypeByStaff(condition);
        }

        /// <summary>
        /// 获取成员所拥有的权限
        /// </summary>
        /// <param name="moduleType"></param>
        /// <param name="staffID"></param>
        /// <param name="moduleMenu"></param>
        /// <param name="funcMenu"></param>
        /// <returns></returns>
        public IList<StaffRolesInfo> ListModuleByStaff(int moduleType, int staffID, string moduleMenu, string funcMenu)
        {
            StaffRolesCondition condition = new StaffRolesCondition();
            condition.ModuleTypeID = moduleType;
            condition.StaffID = staffID;
            condition.ModuleMenu = moduleMenu;
            condition.FuncMenu = funcMenu;
            condition.OrderBy = "ModuleID DESC";
            return dal.ListRolesAuthModuleByStaff(condition);
        }
    }
}
